<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">


      <el-button plain   @click="abc(0)">待入职{{statisticsNum.count0}}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-button plain  @click="abc(1)" >已入职{{statisticsNum.count1}}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-button type="primary"  @click="abc(2)" >RPO{{statisticsNum.count3}}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-button plain @click="abc(3)" >放弃入职{{statisticsNum.count2}}人</el-button>&nbsp;&nbsp;&nbsp;
      <el-form-item  prop="all">
        <el-input
          v-model="queryParams.all"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!--  入职弹出框        -->
    <el-dialog
      title="提示"
      :visible.sync="deb"
      width="30%"
    >
      <div class="block">
        <span class="demonstration">入职日期：</span>
        <el-date-picker
          v-model="employmentDate"
          type="date"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期">
        </el-date-picker>
      </div>

      <span slot="footer" class="dialog-footer">
    <el-button @click="deb = false">取 消</el-button>
    <el-button type="primary" @click="handleUpdate()">确 定</el-button>
  </span>
    </el-dialog>


    <!--淘汰弹出框 -->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <el-form :model="soelForm" :rules="soelRules" ref="soelForm">
        <el-form-item prop="soeliminate" label="淘汰原因">
          <el-select v-model="soelForm.soeliminate" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleDeletes()">确 定</el-button>
      </div>
    </el-dialog>

    <el-table v-loading="loading" :data="managmentlist" @selection-change="handleSelectionChange"
              style="width: 100%" max-height="100%">
<!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="姓名" align="center" prop="name"  width="100" />
      <el-table-column label="电话" align="center" prop="phone"  width="180"  />
      <el-table-column label="应聘职位" align="center" prop="positionApplied"  width="180"  />
      <el-table-column label="岗位类型" align="center" prop="positionType"  width="180" />
      <el-table-column label="企业" align="center" prop="enterprise"  width="100" />
      <el-table-column label="创建人" align="center" prop="uname" width="100"/>
      <el-table-column label="预计到岗日期" align="center" prop="expectedDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expectedDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="到岗日期" align="center" prop="employmentDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.employmentDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0">待入职</span>
          <span v-if="scope.row.status == 3">已入职</span>
        </template>
      </el-table-column>s
      <el-table-column label="操作" width="200" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status == 0"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handles(scope.row.id)"
            v-hasPermi="['system:auitvo:edit']"
          >确定入职</el-button>
          <el-button v-if="scope.row.status == 0"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="dialog(scope.row.id)"
            v-hasPermi="['system:auitvo:edit']"
          >放弃入职</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import {deleteId, giveUp, list, statisticsNum, updateRPO, updateStatus} from "@/api/system/Management";


export default {
  name: "Auitvo",
  data() {
    return {
      deb:false,
      employmentDate:null,
      // 遮罩层
      loading: true,
      id:null,
      resumeId:null,
      isFirst:null,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      /*淘汰原因*/
      soelForm: {
        soeliminate: null
      },
      soelRules: {
        soeliminate: [
          {required: true, message: '淘汰原因不能为空', trigger: 'change'}
        ]
      },
      /*淘汰阶段*/
      ofeliminate:null,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      managmentlist: [],
      statisticsNum:{
        count0:0,
        count1:0,
        count2:0,
        count3:0,
        count4:0
      },
      dialogVisible: false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      options: [{
        value: '',
        label: '请选择'
      },{
        value: '个人原因',
        label: '个人原因'
      }, {
        value: '接收其他offer',
        label: '接收其他offer'
      }, {
        value: '薪资不满意',
        label: '薪资不满意'
      }, {
        value: '职位不满意',
        label: '职位不满意'
      }, {
        value: '工作地点不满意',
        label: '工作地点不满意'
      }, {
        value: '其他',
        label: '其他'
      }],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status:9,
        all:null,
        positionType:null,
        name: null,
        gender: null,
        age: null,
        dateOfBirth: null,
        isMarriage: null,
        isBirth: null,
        ethnicGroup: null,
        politicalOutlook: null,
        documentType: null,
        identificationNumber: null,
        registeredResidence: null,
        phone: null,
        mailbox: null,
        currentAddress: null,
        emergencyContact: null,
        emergencyContactNumber: null,
        schoolName: null,
        education: null,
        major: null,
        isDelete: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      resumeIds:[]

    };
  },
  created() {
    this.getList();
    this.statistics();
  },
  methods: {
    abc(s) {
      var path = null;
      if (s == 0){
        path = 'beemployed'
      }
      if (s == 1){
        path = 'employeds'
      }
      if (s == 2){
        path = 'rpopost'
      }
      if (s == 3){
        path = 'Abemployment'
      }

      this.$router.push({ path:'/employeefiles/Management/'+ path}  ).catch(()=>{})
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then(response => {
        this.managmentlist = response.rows;
        this.total = response.total;
      });
      this.loading = false;
    },
    /** 统计数量 */
    statistics() {
      statisticsNum().then(response => {
        if (response.data !== undefined){
          this.statisticsNum = response.data;
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        status:9,
        positionType:null,
        gender: null,
        age: null,
        dateOfBirth: null,
        isMarriage: null,
        isBirth: null,
        ethnicGroup: null,
        politicalOutlook: null,
        documentType: null,
        identificationNumber: null,
        registeredResidence: null,
        phone: null,
        mailbox: null,
        currentAddress: null,
        emergencyContact: null,
        emergencyContactNumber: null,
        schoolName: null,
        education: null,
        major: null,
        isDelete: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams={
        pageNum: 1,
          pageSize: 10,
          status:9,
          all:null,
          positionType:null,
          name: null,
          gender: null,
          age: null,
          dateOfBirth: null,
          isMarriage: null,
          isBirth: null,
          ethnicGroup: null,
          politicalOutlook: null,
          documentType: null,
          identificationNumber: null,
          registeredResidence: null,
          phone: null,
          mailbox: null,
          currentAddress: null,
          emergencyContact: null,
          emergencyContactNumber: null,
          schoolName: null,
          education: null,
          major: null,
          isDelete: null,
      },
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {

      this.resumeIds = selection.map(a =>a.resumeId)
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 确认入职按钮 */
    handles(id) {
      this.deb =true;
      this.id = id;
    },


    handleUpdate(){
      var id =this.id;
      var employmentDate = this.employmentDate;
      updateRPO(id,this.employmentDate).then(response => {
        this.$modal.msgSuccess("操作成功");
        this.deb = false;
        this.employmentDate = null;
        this.getList();
        this.statistics();
      });
    },
    /**放弃入职按钮 **/
    dialog(id){
      this.id =id;
      this.dialogVisible = true;
    },
    /**淘汰按钮 **/
    handleDeletes(){
      this.$refs["soelForm"].validate(valid => {
        if (valid) {
          var id =this.id;
          var soeliminate  = this.soelForm.soeliminate;
          giveUp(id,soeliminate).then(response => {
            this.dialogVisible =false;
            this.$modal.msgSuccess("操作成功");
            this.getList();
            this.statistics();
          });
        }})
    },

    /** 转移到待入职**/
    handleUpdates(id){
      this.$modal.confirm('是否转移到待入职').then(function() {
        return updateStatus(id);
      }).then(() => {
        this.$modal.msgSuccess("操作成功");
        this.getList();
        this.statistics();
      }).catch(() => {});

    },
    /** 删除**/
    deleteId(id){
      var isDelete = 1;
      this.$modal.confirm('是否删除').then(function() {
        return deleteId(id,isDelete);
      }).then(() => {
        this.$modal.msgSuccess("操作成功");
        this.getList();
        this.statistics();
      }).catch(() => {});

    }







  }
};
</script>
